﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using FieldTemplate;

namespace WpfDevelopHelper
{
    /// <summary>
    /// EnumSet.xaml 的交互逻辑
    /// </summary>
    public partial class EnumSet : UserControl
    {
        public EnumSet()
        {
            InitializeComponent();
        }
    }


    public class EnumFieldSetVm : FieldSetVmBase
    {
        public EnumFieldSetVm()
        {
            FieldName = "年级";
            FieldType = "enum";

            SetPanel = new EnumSet();
            SetPanel.DataContext = this;
            Oneof = "三年级;四年级;五年级";
        }

        [NonSerialized]
        Random rm=new Random();

        private string _Oneof;
        public string Oneof
        {
            get
            {
                return _Oneof;
            }
            set
            {
                _Oneof = value;
                RaisePropertyChanged("Oneof");
            }
        }

        public override string GetFieldValue()
        {
            if(string.IsNullOrWhiteSpace(Oneof))
            {
                return "未设置可能的值";
            }

            var lst= Oneof.Split(';');
            int i = rm.Next(0, lst.Length);
            return lst[i];
        }

        public override Fieldinfo Serialize()
        {
            var tmp = base.Serialize();
            tmp.propertyinfos.Add(new Propertyinfo() { PorpertyName = "Oneof",PropertyType="string", PropertyValue = Oneof.ToString() });

            return tmp;
        }
    }
}
